package com.abluedog.filechannel;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

@Slf4j
public class Main {
    public static void main(String[] args) throws IOException {
        FileChannel channel = new FileInputStream("data.txt").getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        int read = channel.read(byteBuffer);
        while (read!=-1){
            log.debug("read:{}",read);
            byteBuffer.flip();
            while (byteBuffer.hasRemaining()){
                log.debug("byteBuffer:{}",(char)byteBuffer.get());
            }
            byteBuffer.clear();
            read = channel.read(byteBuffer);
        }
    }
}
